package com.itheima.convert;

import com.itheima.dto.user.ExcelUserDto;
import com.itheima.entity.User;
import com.itheima.vo.BriefUserVo;
import com.itheima.vo.organization.OrganizationDetailVo;
import com.itheima.vo.user.UserPersonVo;
import com.itheima.vo.user.UserVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <h1>User转换接口</h1>
 *
 * @author <a href="515857087@qq.com">叶世铭</a>
 * @since 2022/12/6
 */
@Mapper(componentModel = "spring")
public interface UserConvert {

    /**
     * ExcelUserDto -> User
     *
     * @param excelUserDto 用户导入dto
     * @param now          时间
     * @return 用户实体
     */
    @Mapping(target = "createdAt", source = "now")
    User excelUserDtoToUser(ExcelUserDto excelUserDto, LocalDateTime now);


    /**
     * User -> BriefUserVo
     *
     * @param list
     * @return
     */
    List<BriefUserVo> userToBriefUserVo(List<User> list);

    /**
     * User -> BriefUserVo
     *
     * @param user
     * @return
     */
    @Mappings({
            @Mapping(target = "userId", source = "id"),
            @Mapping(target = "userName", source = "name")
    })
    BriefUserVo toBriefUserVo(User user);

    /**
     * User -> UserPersonVo
     *
     * @param user 用户实体
     * @return 用户个人资料
     */
    UserPersonVo toUserPersonVo(User user);

    /**
     * List<User> -> List<OrganizationDetailVo.OrganizationUser>
     * @param userList 用户实体
     * @return 组织详情下的用户信息
     */
    List<OrganizationDetailVo.OrganizationUser> toOrganizationUser(List<User> userList);

    /**
     * User -> OrganizationDetailVo.OrganizationUser
     * @param user 用户实体
     * @return 组织详情下的用户信息
     */
    @Mappings({
            @Mapping(target = "userId",source = "id"),
            @Mapping(target = "userName",source = "name")
    })
    OrganizationDetailVo.OrganizationUser toOrganizationUser(User user);

    /**
     * User -> UserVo
     * @param user 用户实体
     * @return 用户信息vo
     */
    UserVo toUserVo(User user);

}
